package view.dialogs;

import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;

import model.HostAddress;
import model.Subnet;
import view.listeners.CancelListener;
import view.views.dialogButtonViews.CancelButtonPanel;
import controller.Calculator;
import controller.Controller;

public class HostInfoDialog extends  Dialog {


	
	private JPanel leftPanel; 

	public HostInfoDialog(String title) {
		super(title);
		
		
		
		
	}
	
	private JPanel labelPanel(String Text1, String Text2){
		JPanel labelPanel3 = new JPanel();
		 labelPanel3.setLayout(new GridLayout(2,1));
		labelPanel3.add(new JLabel(Text1));
		labelPanel3.add(new JLabel(Text2));
	
		
		return labelPanel3;
		
	}

	@Override
	protected JPanel addContent() {
		HostAddress host = Controller.getInstance().getCurrentHost();
		JPanel rightPanel = new JPanel();
		rightPanel.setLayout(new GridLayout(0, 2));
		
		

		
		
		leftPanel = new JPanel();
		leftPanel.setLayout(new GridLayout(0, 2));
		
		
		leftPanel.add(new JLabel("Subnetz Name: "));
		leftPanel.add(new JLabel(host.getName()));
		
		
		leftPanel.add(new JLabel("Range: "));
		leftPanel.add(new JLabel(String.valueOf(host.getRange())));
		
		
		rightPanel.add(new JLabel("Anzahl von Subnetzen: "));
		rightPanel.add(new JLabel(String.valueOf(host.getSubnetList().size())));
		rightPanel.add(new JLabel(""));
		
		
		
		JPanel southPanel = new JPanel();
		southPanel.setLayout(new GridLayout(0,2,0,10));
		
		southPanel.add(labelPanel("Addresse: ", ""));
		southPanel.add(labelPanel(host.getHostAddress().getAddress(), Calculator.getInstance().convertIPBinary(host.getHostAddress()))
		);
		
		
		
		
		
		
		
		
		
		JPanel Toppanel = new JPanel();
		Toppanel.setLayout(new GridLayout(1, 2,0,10));
		Toppanel.add(leftPanel);
		Toppanel.add(rightPanel);
		
		JPanel panel = new JPanel();
		panel.setLayout(new GridLayout(2,1,10,10));
		panel.add(Toppanel);
		panel.add(southPanel);
		
		JPanel groundPanel  = new JPanel();
		groundPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		groundPanel.add(panel);
		return groundPanel;
	}

	@Override
	protected JPanel addButtons() {
		CancelButtonPanel panel = new CancelButtonPanel();
		
		panel.getCancelButton().addActionListener(new CancelListener(this));
		return panel;
	}

}
